<?php

/**
 * @author dragon.hu add @2016.4.13
 */
defined('BASEPATH') or die('forbidden');

class Actmultiopen_controller extends Controller {

	private $activityList;
    function _init() {
        check_level(50, segment(0), segment(1), segment(2, 'index'));
        
        $sql = "SELECT activityid, activityname FROM dynamic_activity_map WHERE activityid > 1000 AND activityid < 1300";
        $this->db->query($sql);
        while ($n = $this->db->get_array())
        {
        	$this->activityList[$n['activityid']] = $n['activityname'];
        }
    }

    function index() {
     if (is_submit()) {
            $rowdata = $_POST;
            $areaIds = $rowdata['areaIds'];
            $activitylist = $rowdata['activitylist'];
            //var_dump($rowdata);
            //exit();
            $areas = get_area_list_url();
            if (in_array('0', $areaIds))
            {
            	foreach ($areas as $k => $v)
            	{
            		$tmpdbconn = getTmpDbConnect(PLATFORM_ALL, 'all', $k, DBTYPE_GAMESERVER);
            		$sql = "SELECT * FROM dynamic_activity_time order by id asc";
            		$tmpdbconn->query($sql);
            		while ($n = $tmpdbconn->get_array())
            		{
            			if (in_array($n['activityid'], $activitylist))
            			{
            				if($n['isopen'] == 0)
            				{
            					$n['isopen'] = 1;  //开启
            					$value['id'] = $n['id'];
            					$value['isOpen'] = $n['isopen'];
            					$value['startTime'] = strtotime($n['starttime']);
            					$value['endTime'] = strtotime($n['endtime']);
            					$value['isEver'] = $n['isever'];
            					$value['level'] = $n['level'];
            					$value['times'] = $n['times'];
            					$value['describe'] = $n['describe'];
            					$value['name'] = $n['name'];
            					$value['rules'] = $n['rules'];
            					$value['string_time'] = strtotime($n['string_time']);
            					$value['defaultstate'] = $n['defaultstate'];
            					$value['subid'] = $n['subid'];
            					$value['sequence'] = $n['sequence'];
            					$value['dayreset'] = $n['dayreset'];
            					$result = vpost($v . array_to_stringparam($value) . "action=11&id={$value['id']}");
            				}
            			}
            		}
            		echo "<script>alert('server " .$k. " success!')</script>";
            	}
            }
            else
            {
            	foreach ($areaIds as $k => $v)
            	{
            		if ($areas[$v])
            		{
            			$tmpdbconn = getTmpDbConnect(PLATFORM_ALL, 'all', $v, DBTYPE_GAMESERVER);
            			$sql = "SELECT * FROM dynamic_activity_time order by id asc";
            			$tmpdbconn->query($sql);
            			while ($n = $tmpdbconn->get_array())
            			{
            				if (in_array($n['activityid'], $activitylist))
            				{
            					if($n['isopen'] == 0)
            					{
            						$n['isopen'] = 1;  //开启
            						$value['id'] = $n['id'];
            						$value['isOpen'] = $n['isopen'];
            						$value['startTime'] = strtotime($n['starttime']);
            						$value['endTime'] = strtotime($n['endtime']);
            						$value['isEver'] = $n['isever'];
            						$value['level'] = $n['level'];
            						$value['times'] = $n['times'];
            						$value['describe'] = $n['describe'];
            						$value['name'] = $n['name'];
            						$value['rules'] = $n['rules'];
            						$value['string_time'] = strtotime($n['string_time']);
            						$value['defaultstate'] = $n['defaultstate'];
            						$value['subid'] = $n['subid'];
            						$value['sequence'] = $n['sequence'];
            						$value['dayreset'] = $n['dayreset'];
            						$result = vpost($areas[$v] . array_to_stringparam($value) . "action=11&id={$value['id']}");
            					}
            				}
            			}
            			echo "<script>alert('server " .$v. " success!')</script>";
            		}
            	}
            	
            }
        }

        set_area_list_view("arealist");
        $params = array('multiple' => 'multiple', 'class' => 'multiselect', 'id' => 'activitylist');
        $this->view->assign("activitylist", str_replace(array("\r\n", "\n", "\n"), '', $this->form->select("activitylist", $this->activityList, '0', $params, false)));
        $this->view->display("activity/actmultiopen/index",$data);
    }

}

?>
